#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "js_context.h"

#include <QWebChannel>
#include <QWebEngineView>
#include <QFile>
#include <QDebug>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent),
      ui(new Ui::MainWindow),
      m_jsContext(new JsContext(this))
{
    ui->setupUi(this);
    
    QWebEngineView *webView = new QWebEngineView(this);
    QWebChannel *webChannel = new QWebChannel(this);
    webChannel->registerObject("context_qt", m_jsContext);
    webView->page()->setWebChannel(webChannel);

    setCentralWidget(webView);

    QFile file("/home/jake/workspace/demo/cxx/qt/webchannel/test.html");
    file.open(QIODevice::ReadOnly);
    webView->setHtml(file.readAll());
}

MainWindow::~MainWindow()
{
    delete ui;
}

